---
version: 2
jobs:
  node-latest: &test
    docker:
      - image: node:latest
    working_directory: ~/cli
    steps:
      - checkout
      - restore_cache: &restore_cache
          keys:
            - v1-npm-{{checksum ".circleci/config.yml"}}-{{checksum "yarn.lock"}}
            - v1-npm-{{checksum ".circleci/config.yml"}}
      - run:
          name: Install dependencies
          command: yarn
      - run:
          name: Build plugin
          command: yarn prepack
      - run:
          name: Testing
          command: yarn test
      - run:
          name: Submitting code coverage to codecov
          command: |
            ./node_modules/.bin/nyc report --reporter text-lcov > coverage.lcov
            curl -s https://codecov.io/bash | bash
  node-8:
    <<: *test
    docker:
      - image: node:8
  node-10:
    <<: *test
    docker:
      - image: node:10
  cache:
    <<: *test
    steps:
      - checkout
      - run:
          name: Install dependencies
          command: yarn
      - save_cache:
          key: v1-npm-{{checksum ".circleci/config.yml"}}-{{checksum "yarn.lock"}}
          paths:
            - ~/cli/node_modules
            - /usr/local/share/.cache/yarn
            - /usr/local/share/.config/yarn

workflows:
  version: 2
  "sfdx-allure":
    jobs:
      - node-latest
      - node-8
      - node-10
      - cache:
          filters:
            tags:
              only: /^v.*/
            branches:
              ignore: /.*/
